<template>
  <div class="tuijian">
    <el-dialog title="补录领导批示" :visible.sync="leaderApproveVisible" width="80%" top="20px" :close-on-click-modal="false" :close-on-press-escape="false">
      <leaderApprove v-bind:personId='personId' :step='selStep' :szData="selectData.szData" @closeDialog="closeAndRefresh"></leaderApprove>
    </el-dialog>
    <el-dialog title="批示意见/办理提示" :visible.sync="noticeVisible" width="95%">
      <notice :timestamp="timestamp" :noticePersonId="noticePersonId" :step="selStep" @refresh="refresh"></notice>
      <div slot="footer" class="dialog-footer" style="overflow:hidden">
        <el-button @click.native="noticeVisible = false" style="float:right">关闭</el-button>
      </div>
    </el-dialog>
    <el-breadcrumb separator=">">
      <el-breadcrumb-item :to="{ path: '/' }">系统首页</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/selection' }">干部选任</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/selection/candidateReport' }">事前报告</el-breadcrumb-item>
    </el-breadcrumb>
    <section class="wboxnoborder">
      <div :style="'height:'+tableHeight+'px'">
        <el-scrollbar style="height: calc(100% + 16px);">
          <el-tabs v-model="activeName" type="card" @tab-click="tabsClick" style="margin:15px">
            <el-tab-pane label="待办理" name="first">
              <span slot="label" v-if="countnum1>0" class="pointtab"><el-badge :value="countnum1" class="item">待办理</el-badge></span>
              <el-table
                ref="tableData0"
                @selection-change="handleSelectionChange0"
                :data="tableData0"
                border v-loading="loading0">
                <el-table-column
                  type="selection"
                  width="45">
                </el-table-column>
                <el-table-column
                  prop="jobName"
                  label="动议岗位职务"
                  width="200">
                </el-table-column>
                <el-table-column
                  prop="jobLevel"
                  label="动议岗位职级"
                  width="200">
                </el-table-column>
                <el-table-column
                  prop="unitName"
                  label="动议岗位单位"
                  show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                  prop="realName"
                  label="姓名"
                  width="100">
                </el-table-column>
                <el-table-column
                  label="操作" width="150">
                  <template slot-scope="scope">
                    <el-button @click="goTuijianDetail(scope.row)" type="primary">办理</el-button>
                  </template>
                </el-table-column>
              </el-table>
              <select-group :backflag="false" :selectData="selectData" :selectPerson="selectPerson0" :selApi="selApi" :selStep="selStep" @getList="getList0"></select-group>
            </el-tab-pane>
            <el-tab-pane label="办理中" name="doing" v-if="false">
              <span slot="label" v-if="countnum2>0" class="pointtab"><el-badge :value="countnum2" class="item">办理中</el-badge></span>
              <el-table
                :data="tableData1"
                border v-loading="loading1">
                <el-table-column
                  prop="jobName"
                  label="动议岗位职务"
                  width="200">
                </el-table-column>
                <el-table-column
                  prop="jobLevel"
                  label="动议岗位职级"
                  width="200">
                </el-table-column>
                <el-table-column
                  prop="unitName"
                  label="动议岗位单位"
                  width="200"
                  show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                  prop="realName"
                  label="姓名"
                  width="100">
                </el-table-column>
                <el-table-column
                  prop="receiveUserName"
                  label="办理人">
                </el-table-column>
              </el-table>
            </el-tab-pane>
            <el-tab-pane label="已办理" name="second">
              <span slot="label" v-if="countnum3>0" class="pointtab"><el-badge :value="countnum3" class="item">已办理</el-badge></span>
              <el-table
                :data="tableData2"
                border
                @selection-change="handleSelectionChange"
                v-loading="loading2">
                <el-table-column
                  type="selection"
                  width="45">
                </el-table-column>
                <el-table-column
                  prop="jobName"
                  label="动议岗位职务"
                  width="200">
                </el-table-column>
                <el-table-column
                  prop="jobLevel"
                  label="动议岗位职级"
                  width="200">
                </el-table-column>
                <el-table-column
                  prop="unitName"
                  label="动议岗位单位"
                  show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                  prop="realName"
                  label="姓名"
                  width="100">
                </el-table-column>
                <el-table-column
                  prop="stepCandidateReportUsername"
                  label="办理人"
                  width="100">
                </el-table-column>
                <el-table-column
                  label="操作"
                  width="250">
                  <template slot-scope="scope">
                    <el-button @click="detailShow(scope.row)" type="primary">查看</el-button>
                    <el-button @click="addLeaderApprove(scope.row.id)">补录领导批示</el-button>
                  </template>
                </el-table-column>
              </el-table>
              <select-group :backflag="false" :selectData="selectData" :selectPerson="selectPerson" :selApi="selApi" :selStep="selStep" @getList="getList2"></select-group>
            </el-tab-pane>
            <el-tab-pane label="已批示" name="third">
              <span slot="label" v-if="countnum4>0" class="pointtab"><el-badge :value="countnum4" class="item">已批示</el-badge></span>
              <el-table
                :data="tableData3"
                border
                v-loading="loading3">
                <el-table-column
                  prop="jobName"
                  label="动议岗位职务"
                  width="200">
                </el-table-column>
                <el-table-column
                  prop="jobLevel"
                  label="动议岗位职级"
                  width="200">
                </el-table-column>
                <el-table-column
                  prop="unitName"
                  label="动议岗位单位"
                  show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                  prop="realName"
                  label="姓名"
                  width="100">
                </el-table-column>
                <el-table-column
                  prop="stepCandidateReportUsername"
                  label="办理人"
                  width="100">
                </el-table-column>
                <el-table-column label="批示意见/办理提示" width="250">
                  <template slot-scope="scope">
                    <el-popover placement="bottom" width="600" trigger="hover">
                      <notice :timestamp="timestamp" :noticePersonId="scope.row.busCandidatePersonId" step="12" @refresh="refresh"></notice>
                      <el-button size="small" slot="reference" type="primary" @click="showNotice(scope.row.busCandidatePersonId)">查看详情</el-button>
                    </el-popover>
                  </template>
                </el-table-column>
                <el-table-column
                  label="操作">
                  <template slot-scope="scope">
                    <el-button @click="goTuijianDetail2(scope.row)" type="primary" >办理</el-button>
                    <el-button @click="addLeaderApprove(scope.row.busCandidatePersonId)">补录领导批示</el-button>
                  </template>
                </el-table-column>
              </el-table>
            </el-tab-pane>
          </el-tabs>
        </el-scrollbar>
      </div>
    </section>
  </div>
</template>

<script>
import notice from '../common/Notice'
import selectGroup from '../common/SelectGroup2'
import leaderApprove from '../common/leaderApprove'
export default {
  name: 'candidateReport',
  components: {
    notice,
    selectGroup,
    leaderApprove
  },
  data () {
    return {
      timestamp: '',
      personId: '',
      leaderApproveVisible: false,
      countnum1: 0,
      countnum2: 0,
      countnum3: 0,
      countnum4: 0,
      loading0: false,
      loading1: false,
      loading2: false,
      loading3: false,
      tableHeight: 100,
      activeName: 'first',
      noticeVisible: false,
      noticePersonId: '',
      tableData0: [],
      tableData1: [],
      tableData2: [],
      tableData3: [],
      noticeTit: '办理提示',
      noticeData: [],
      noticeTit2: '批示意见',
      noticeData2: [],
      selectData: {
        hjData: [
        ],
        szData: [
        ],
        cnData: [
        ],
        yyData: []
      },
      selectPerson0: [],
      selectPerson: [],
      selApi: 'api/selection/candidateReport/saveApprove',
      selStep: 12
    }
  },
  methods: {
    refresh () {
      this.getList3()
      this.getList2()
      this.timestamp = new Date().getTime()
    },
    closeAndRefresh () {
      this.leaderApproveVisible = false
      this.getList3()
      this.getList2()
      this.timestamp = new Date().getTime()
    },
    addLeaderApprove (id) {
      this.leaderApproveVisible = true
      this.personId = id
    },
    showNotice (id) {
      console.log('show notice id:', id)
      this.noticePersonId = id
      this.noticeVisible = true
      this.timestamp = new Date().getTime()
    },
    loadSelectData2 () {
      console.log('获取司长名单')
      this.selectData = {
        hjData: [
        ],
        szData: [
        ],
        cnData: [
        ],
        yyData: []
      }
      this.$http
        .get(this.$http.defaults.selectionAPI + `api/selection/auth/getUsersByRole?roletype=3`)
        .then(response => {
          if (response.data.success) {
            this.selectData.cnData = []
            for (let i = 0; i < response.data.result.length; i++) {
              this.selectData.cnData.push(response.data.result[i])
            }
          } else {
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(error => {
          console.log(error)
          this.$message({
            message: '获取失败:' + error,
            type: 'error'
          })
        })
      this.$http
        .get(this.$http.defaults.selectionAPI + `api/selection/auth/getUsersByRole?roletype=2`)
        .then(response => {
          if (response.data.success) {
            for (let i = 0; i < response.data.result.length; i++) {
              if (response.data.result[i].roleName === 'ROLE_sizhang' || response.data.result[i].manageDep.indexOf(localStorage.getItem('unitName')) > -1) {
                this.selectData.szData.push(response.data.result[i])
              }
            }
          } else {
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(error => {
          console.log(error)
          this.$message({
            message: '获取失败:' + error,
            type: 'error'
          })
        })
      this.$http
        .get(this.$http.defaults.selectionAPI + `api/selection/home/getCommonlyOpinions?step=12`)
        .then(response => {
          if (response.data.success) {
            this.selectData.yyData = response.data.result
          } else {
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(error => {
          console.log(error)
          this.$message({
            message: '获取失败:' + error,
            type: 'error'
          })
        })
    },
    loadSelectData () {
      this.selectData = {
        hjData: [
        ],
        szData: [
        ],
        cnData: [
        ],
        yyData: []
      }
      this.$http
        .get(this.$http.defaults.selectionAPI + `api/selection/auth/getUsersByRole?roletype=3`)
        .then(response => {
          if (response.data.success) {
            this.selectData.cnData = []
            for (let i = 0; i < response.data.result.length; i++) {
              this.selectData.cnData.push(response.data.result[i])
            }
          } else {
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(error => {
          console.log(error)
          this.$message({
            message: '获取失败:' + error,
            type: 'error'
          })
        })
      this.$http
        .get(this.$http.defaults.selectionAPI + `api/selection/home/getCommonlyOpinions?step=12`)
        .then(response => {
          if (response.data.success) {
            this.selectData.yyData = response.data.result
          } else {
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(error => {
          console.log(error)
          this.$message({
            message: '获取失败:' + error,
            type: 'error'
          })
        })
    },
    handleSelectionChange0 (val) {
      console.log('handleSelectionChange0:', val)
      this.selectPerson0 = [...val]
    },
    handleSelectionChange (val) {
      console.log('handleSelectionChange:', val)
      this.selectPerson = [...val]
    },
    tabsClick (tab) {
      if (tab.name === 'first') {
        console.log('first in')
        this.getList0()
      } else if (tab.name === 'doing') {
        this.getList1()
      } else if (tab.name === 'second') {
        this.getList2()
      } else if (tab.name === 'third') {
        this.getList3()
      }
    },
    getList0 () {
      this.getNum()
      this.loading0 = true
      let url = this.$http.defaults.selectionAPI + 'api/selection/candidateReport/getNotProcessedPersons?sended=0'
      // console.log(url)
      this.$http.get(url, {}).then(res => {
        console.log('get list succ:', res)
        if (res.data.success === true) {
          let rs = res.data.result
          this.tableData0 = rs
          this.$nextTick(() => {
            this.tableData0.forEach(row => {
              if (row.personId === this.$route.params.selectPersonId) {
                this.$refs.tableData0.toggleRowSelection(row)
                this.$route.params.selectPersonId = null
              }
            })
          })
          this.loading0 = false
        } else {
          this.loading = false
          this.$message({
            message: '数据获取失败',
            type: 'error'
          })
        }
      })
      this.loadSelectData()
    },
    getList1 () {
      this.getNum()
      this.loading1 = true
      let url = this.$http.defaults.selectionAPI + 'api/selection/candidateReport/getNotProcessedPersons?sended=1'
      // console.log(url)
      this.$http.get(url, {}).then(res => {
        console.log('get list succ:', res)
        if (res.data.success === true) {
          let rs = res.data.result
          this.tableData1 = rs
          this.loading1 = false
        } else {
          this.loading1 = false
          this.$message({
            message: '数据获取失败',
            type: 'error'
          })
        }
      })
    },
    getList2 () {
      this.getNum()
      this.loading2 = true
      let url = this.$http.defaults.selectionAPI + 'api/selection/candidateReport/getProcessedNotApprove'
      // console.log(url)
      this.$http.get(url, {}).then(res => {
        console.log('get list22 succ:', res)
        if (res.data.success === true) {
          let rs = res.data.result
          this.tableData2 = rs
          this.loading2 = false
        } else {
          this.loading2 = false
          this.$message({
            message: '数据获取失败',
            type: 'error'
          })
        }
      })
      this.loadSelectData2()
    },
    getList3 () {
      this.timestamp = new Date().getTime()
      this.getNum()
      this.loading3 = true
      let url = this.$http.defaults.selectionAPI + 'api/selection/approve/getUserApproveList'
      // console.log(url)
      this.$http.post(url, {
        step: 12
      }).then(res => {
        console.log('get list33 succ:', res)
        if (res.data.success === true) {
          let rs = res.data.result
          this.tableData3 = rs
          this.loading3 = false
        } else {
          this.loading3 = false
          this.$message({
            message: '数据获取失败',
            type: 'error'
          })
        }
      })
      this.loadSelectData2()
    },
    getNum () {
      let url = this.$http.defaults.selectionAPI + 'api/selection/statnum/candidateReport/getStatNum'
      // console.log(url)
      this.$http.get(url).then(res => {
        if (res.data.success === true) {
          this.countnum1 = res.data.result.countnum1
          this.countnum2 = res.data.result.countnum2
          this.countnum3 = res.data.result.countnum3
          this.countnum4 = res.data.result.countnum4
        } else {
          this.$message({
            message: '数据获取失败',
            type: 'error'
          })
        }
      })
    },
    goTuijianDetail (item) {
      console.log(item)
      item.edit = false
      this.$router.push({
        name: 'candidateReportDetail',
        params: item
      })
    },
    goTuijianDetail2 (item) {
      console.log(item)
      item.edit = true
      this.$router.push({
        name: 'candidateReportDetail',
        params: item
      })
    },
    detailShow (item) {
      console.log(item)
      this.$router.push({
        name: 'candidateReportDetailShow',
        params: item
      })
    },
    tableresize (obj) {
      var clientHeight = 0
      if (document.body.clientHeight && document.documentElement.clientHeight) {
        clientHeight = (document.body.clientHeight < document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight
      } else {
        clientHeight = (document.body.clientHeight > document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight
      }
      obj.$nextTick(function () {
        obj.tableHeight = clientHeight - 165
      })
    }
  },
  mounted () {
    this.getList0()
    let params = this.$route.params
    if (params && params.step) {
      console.log('in params')
      if (params.step === 1) {
        this.activeName = 'first'
        this.getList1()
      }
      if (params.step === 2) {
        this.activeName = 'second'
        this.getList2()
      }
      if (params.step === 3) {
        this.activeName = 'third'
        this.getList3()
      }
    }
    this.tableresize(this)
    let _this = this
    window.onresize = function windowResize () {
      // 通过捕获系统的onresize事件触发我们需要执行的事件
      _this.tableresize(_this)
    }
  }
}
</script>

<style>
.tuijian .el-table--border td, .el-table--border th, .el-table__body-wrapper .el-table--border.is-scrolling-left~.el-table__fixed{
  border-bottom:1px solid #95B8E7;
}
.tuijian .el-table td, .el-table th.is-leaf{
  border-right:1px solid #95B8E7;
}
  .tuijian .wboxnoborder .el-table{
    border: #95B8E7 solid 1px;
  }
  .tuijian .wboxnoborder .el-table th{
    font-weight: normal;
    background-image: linear-gradient(to bottom , #f8f8f8, #efefef);
    text-align: center;
    border-right: #95B8E7 solid 1px;
    border-bottom: #95B8E7 solid 1px;
    min-height: 30px;
    line-height:30px;
  }
  .tuijian .wboxnoborder .el-table td, .el-table th{
    padding:0;
    font-size:var(--size14) !important;
    line-height: 20px;
    font-family: '宋体';
    text-align: center;
  }
  .tuijian .el-table__row{
    height: 50px;
  }
</style>
<style scoped>
  .tuijian .cell i {
    width: 30px;
    height: 30px;
    background-position: center center;
    background-repeat: no-repeat;
    float: center;
    display: block;
    margin: 0 auto;
  }
  .workflowmsg ul{
    background:#F5F7FA;
    margin:0 20px 20px;
    padding:10px 0;
  }
  .workflowmsg li{
    padding:0;
    list-style: none;
    margin-left:20px;
    line-height: 200%;
    font-size:var(--size) !important;
  }
  h1{
    font-size:var(--size16) !important;
    font-weight: bolder;
    height: 30px;
    border-bottom: 1px solid #95B8E7;
    font-family: '宋体';
    line-height: 30px;
    color: #000;
    padding-left:10px;
    background-image: linear-gradient(to bottom , #EEF4FF, #E0ECFF);
    margin:0;
  }
  h3{
    font-size:var(--size16) !important;
    font-weight: bolder;
    padding-left: 20px;
  }
  .el-pagination{
    float: left;
    padding:7px 10px;
  }
  .wboxs{
    padding:5px 15px;
    width: calc(100% - 30px);
    background: #fff;
    border: 1px solid #95B8E7;
    margin:0 10px;
    overflow: hidden;
  }
  .tuijian .wboxnoborder{
    padding:0;
    width: calc(100% - 0px);
    background: #fff;
    margin:0 10px;
    overflow: hidden;
  }
</style>
